<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
class Class_AFCS_AR extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table = "T_MON_CELLD_F";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey = "id";
	
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "flier_date";
	 
//	 protected $_cols  = array(
//	 	"login_id"   => array(AOKI_VARTYPE_STR),
//		"user_name"  => array(AOKI_VARTYPE_STR),
//		"auth"       => array(AOKI_VARTYPE_STR),
//	    "email"      => array(AOKI_VARTYPE_STR),
//		"login_pwd"  => array(AOKI_VARTYPE_STR),
//	 );
	
//	 protected $_checks  = array(
//		"login_id"   => array( "EXIST" ,"ALNUM" ),
//		"login_pwd"  => array( "EXIST" ,"ALNUM" ),
//		"user_name"  => array( "EXIST" ),
//		"auth"       => array( "EXIST" ,"NUM" ),
//		"email"      => array( "EXIST" ,"EMAIL" ),
//		"login_ng"   => array("NUM" ),
//		
//	 );
//	 
//	 //maxlength 
//	 protected $_maxlens  = array(
//		"login_id"   =>  20 ,
//		"user_name"  =>  20 ,
//		"auth"       =>  1 ,
//		"email"      =>  100 ,
//		"login_pwd"  =>  200,
//		"login_ng"   =>  1
//	 );
	
	 public function search($where ,&$page = NULL ,$aja_cd= null ){	
		$sqlfrom = " from   T_MON_CELLD_F " .
				" inner join M_PATTERN on T_MON_CELLD_F.pattern_cd = M_PATTERN.pattern_cd " .
				" inner join M_MATRIX_VER ON T_MON_CELLD_F.matrix_cd =  M_MATRIX_VER.matrix_cd  AND T_MON_CELLD_F.title_cd = M_MATRIX_VER.id " .
				" inner join M_MATRIX_TERM ON T_MON_CELLD_F.matrix_cd = M_MATRIX_TERM.matrix_cd  " .
				" inner join M_SHOP ON T_MON_CELLD_F.shop_cd = M_SHOP.shop_cd  ";
		if (!empty($aja_cd)) {
			$sqlfrom = $sqlfrom. " inner join  (select shop_cd from  M_AJAREKS a inner join M_LOGIN b on  a.userid = b.id  " .
				" where b.login_id = '{$aja_cd}')  aja on T_MON_CELLD_F.shop_cd = aja.shop_cd  " ;
		}
		$sql = "SELECT *,M_PATTERN.pattern_name ".$sqlfrom;
		$sqlcnt = "SELECT COUNT(*) AS cnt ".$sqlfrom;
		
		return  parent::search($where ,$page ,$sql,$sqlcnt);

	}

//	 public function search_csv($where  ){	
//		$sql = "SELECT a.*,b.ins_co_name,(select  user_name FROM {$this->_table} where  id  = a.u_user) as m_user_name from {$this->_table} a ";
//		$sql = $sql." LEFT JOIN  M_INS_CO b ON a.ins_co_cd = b.ins_co_cd ";
//		$page = null;
//		return  parent::search($where ,$page ,$sql);
//	}
	
}

?>